package com.sip.stream.utils.zfy.camera;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.HandlerThread;
import android.os.SystemClock;
import android.util.Log;
import android.view.Surface;
import com.gosuncn.zfyluancher.ZFYLauncherJNI;
import com.serenegiant.usb.IButtonCallback;
import com.serenegiant.usb.IFrameCallback;
import com.serenegiant.usb.IStatusCallback;
import com.serenegiant.usb.Size;
import com.serenegiant.usb.USBMonitor;
import com.serenegiant.usb.UVCCamera;
import com.sip.stream.R;
import com.sip.stream.media.ZFYCameraParameters;
import com.sip.stream.media.ZFYMediaManager;
import com.sip.stream.utils.zfy.config.ZFYMediaConfig;
import com.sip.stream.utils.zfy.yuv.YUVToolFactory;

import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.subjects.BehaviorSubject;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class UVCCameraHelper extends AbstractZFYCamera implements IStatusCallback, IFrameCallback, IButtonCallback {
    private static final String TAG = "UVCCameraHelper";

    private static String deviceNode = "/sys/class/gpio/ircut";
    private HandlerThread backgroundThread;
    private UVCCamera camera;
    private BehaviorSubject<Boolean> closeCameraSubject;
    private Context context;
    private Surface mPreviewSurface;
    private BehaviorSubject<AbstractZFYCamera> openCameraSubject;
    private USBMonitor.UsbControlBlock usbControlBlock;
    private USBMonitor usbMonitor;
    private Size videoSize;
    private AtomicBoolean needCaptrue = new AtomicBoolean();
    private ZFYCameraStatus status = new ZFYCameraStatus();
    private BehaviorSubject<Boolean> requestPermissionBehavior = null;
    private AtomicBoolean isStartPreview = new AtomicBoolean(false);
    private long lastTime = 0;
    private int fpsCounter = 0;

    public void switchDevice(boolean z) {
    }

    @Override
    public void changeInfraredLight(boolean z) {
    }

    @Override
    public boolean isLocked() {
        return false;
    }

    @Override
    public void onButton(int i, int i2) {
    }

    @Override
    public void setCurrentZoom(float f) {
    }

    @Override
    public boolean setFlashMode(int i) {
        return false;
    }

    @Override
    public void setHdr(boolean z) {
    }

    @Override
    public void setInfraredLightMode(boolean z) {
    }

    public UVCCameraHelper(Context context) {
        this.context = context;
    }

    private Context getContext() {
        return this.context;
    }

    public Single<AbstractZFYCamera> openCamera() {
        BehaviorSubject<AbstractZFYCamera> behaviorSubject = this.openCameraSubject;
        if (behaviorSubject != null) {
            return behaviorSubject.firstOrError();
        }
        this.openCameraSubject = BehaviorSubject.create();
        setUpUSBMonitor();
        Log.i(TAG, "setUpUSBMonitor");
        return this.openCameraSubject.firstOrError().doFinally(new Action() {
            @Override
            public  void run() {
                UVCCameraHelper.this.openCameraSubject = null;
            }
        });
    }


    private void requestPermission(UsbDevice usbDevice) {
        if (this.requestPermissionBehavior == null) {
            this.requestPermissionBehavior = BehaviorSubject.create();
            UsbDevice usbDevice2 = null;
            Iterator<UsbDevice> it = ((UsbManager) getContext().getSystemService(Context.USB_SERVICE)).getDeviceList().values().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                UsbDevice next = it.next();
                if (next.getDeviceId() == usbDevice.getDeviceId()) {
                    usbDevice2 = next;
                    break;
                }
            }
            String str = TAG;
            Log.w(str, "requestPermission " + usbDevice2.getDeviceName());
            if (!this.usbMonitor.requestPermission(usbDevice2)) {
                Log.w(str, "not need to RequestPermission");
                this.requestPermissionBehavior.onNext(Boolean.TRUE);
                return;
            }
            this.requestPermissionBehavior.onNext(Boolean.FALSE);
        }
    }

    private void setUpUSBMonitor() {
        Log.w(TAG, "setUpUSBMonitor");
        if (this.usbMonitor != null) {
            Log.w(TAG, "usbMonitor != null");
            return;
        }
        USBMonitor uSBMonitor = new USBMonitor(getContext(), new USBMonitor.OnDeviceConnectListener() {
            @Override
            public void onAttach(UsbDevice usbDevice) {
                Log.w(UVCCameraHelper.TAG, "onAttach " + usbDevice.getDeviceName());
            }

            @Override
            public void onDettach(UsbDevice usbDevice) {
                Log.w(UVCCameraHelper.TAG, "onDettach " + usbDevice.getDeviceName());
            }

            @Override
            public void onConnect(UsbDevice usbDevice, USBMonitor.UsbControlBlock usbControlBlock, boolean z) {
                Log.w(UVCCameraHelper.TAG, "onConnect: " + usbDevice.getDeviceName());
                UVCCameraHelper.this.doAfteronConnect(usbControlBlock);
            }

            @Override
            public void onDisconnect(UsbDevice usbDevice, USBMonitor.UsbControlBlock usbControlBlock) {
                Log.w(UVCCameraHelper.TAG, "onDisconnect " + usbDevice.getDeviceName());
                UVCCameraHelper.this.closeCameraAction().subscribe(new SingleObserver<Boolean>() {
                    @Override
                    public void onError(Throwable th) {
                    }

                    @Override
                    public void onSubscribe(Disposable disposable) {
                    }

                    @Override
                    public void onSuccess(Boolean bool) {
                    }
                });
            }

            @Override
            public void onCancel(UsbDevice usbDevice) {
                Log.w(UVCCameraHelper.TAG, "onDisconnect");
            }
        });
        this.usbMonitor = uSBMonitor;
        uSBMonitor.register();
        List<UsbDevice> deviceList = this.usbMonitor.getDeviceList();
        if (deviceList.size() == 1) {
            this.usbMonitor.requestPermission(deviceList.get(0));
        }
        switchDevice(false);
    }

    public void doAfteronConnect(USBMonitor.UsbControlBlock usbControlBlock) {
        Single.just(usbControlBlock).observeOn(getBackgroundScheduler()).flatMap(new Function() {
            @Override
            public Object apply(Object obj) {
                return UVCCameraHelper.this.m657x3d05372((USBMonitor.UsbControlBlock) obj);
            }
        }).timeout(5L, TimeUnit.SECONDS, Single.error(new Exception("openCamera timeout"))).doOnSuccess(new Consumer() {
            @Override
            public  void accept(Object obj) {
                UVCCameraHelper.this.camera = (UVCCamera) obj;
            }
        }).subscribe(new SingleObserver<UVCCamera>() {
            @Override
            public void onSubscribe(Disposable disposable) {
            }

            @Override
            public void onSuccess(UVCCamera uVCCamera) {
                Log.w(UVCCameraHelper.TAG, "doAfteronConnect onSuccess");
                if (UVCCameraHelper.this.openCameraSubject != null) {
                    UVCCameraHelper.this.openCameraSubject.onNext(UVCCameraHelper.this);
                    UVCCameraHelper.this.openCameraSubject = null;
                }
            }

            @Override
            public void onError(Throwable th) {
                Log.e(UVCCameraHelper.TAG, "" + th.getMessage());
                th.printStackTrace();
                if (UVCCameraHelper.this.openCameraSubject != null) {
                    UVCCameraHelper.this.openCameraSubject.onError(th);
                    UVCCameraHelper.this.openCameraSubject = null;
                }
            }
        });
    }


    public Single<UVCCamera> m657x3d05372(USBMonitor.UsbControlBlock usbControlBlock) {
        UVCCamera uVCCamera = this.camera;
        if (uVCCamera != null) {
            return Single.just(uVCCamera);
        }
        UVCCamera uVCCamera2 = new UVCCamera();
        try {
            uVCCamera2.open(usbControlBlock);
            uVCCamera2.setStatusCallback(this);
            this.usbControlBlock = usbControlBlock;
            String str = uVCCamera2.getDeviceName() + "vid" + uVCCamera2.getUsbControlBlock().getVenderId() + "pid" + uVCCamera2.getUsbControlBlock().getProductId();
            Log.i(TAG, str);
            Size size = "/dev/bus/usb/001/002vid2pid1792".equalsIgnoreCase(str) ? new Size(0, 0, 0, 640, 480) : null;
            try {
                if (size != null) {
                    this.videoSize = size;
                } else {
                    this.videoSize = chooseUVCSize(uVCCamera2.getSupportedSizeList(), 1, 0);
                }
                if (this.videoSize != null) {
                    Log.w(TAG, "setPreviewSize: " + this.videoSize + " FRAME_FORMAT_MJPEG");
                    uVCCamera2.setPreviewSize(this.videoSize.width, this.videoSize.height, 1);
                } else {
                    Log.e(TAG, "setPreviewSize videoSize null");
                }
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "setPreviewSize error " + e.getMessage());
                try {
                    if (size != null) {
                        this.videoSize = size;
                    } else {
                        this.videoSize = chooseUVCSize(uVCCamera2.getSupportedSizeList(), 1, 0);
                    }
                    if (this.videoSize != null) {
                        Log.w(TAG, "setPreviewSize: " + this.videoSize + " FRAME_FORMAT_YUYV");
                        uVCCamera2.setPreviewSize(this.videoSize.width, this.videoSize.height, 5);
                    } else {
                        Log.e(TAG, "setPreviewSize videoSize null");
                    }
                } catch (IllegalArgumentException e2) {
                    Log.e(TAG, "setPreviewSize error " + e.getMessage());
                    uVCCamera2.destroy();
                    return Single.error(e2);
                }
            }
            Log.w(TAG, "setUpCamera " + this.videoSize);
            this.cameraParameters.setVideoWidth(this.videoSize.width);
            this.cameraParameters.setVideoHeight(this.videoSize.height);
            this.cameraParameters.setCaptrueHeight(this.videoSize.height);
            this.cameraParameters.setCaptrueWidth(this.videoSize.width);
            this.cameraParameters.setRemoteWidth(this.videoSize.width);
            this.cameraParameters.setRemoteHeight(this.videoSize.height);
            return Single.just(uVCCamera2);
        } catch (Exception e3) {
            return Single.error(e3);
        }
    }

    private Single<UVCCamera> startPreview(UVCCamera uVCCamera) {
        Surface surface = this.mPreviewSurface;
        if (surface != null) {
            surface.release();
            this.mPreviewSurface = null;
        }
        SurfaceTexture previewSurfaceTexture = getPreviewSurfaceTexture();
        if (previewSurfaceTexture != null) {
            Surface surface2 = new Surface(previewSurfaceTexture);
            this.mPreviewSurface = surface2;
            uVCCamera.setPreviewDisplay(surface2);
            uVCCamera.setFrameCallback(new IFrameCallback() {
                @Override
                public  void onFrame(ByteBuffer byteBuffer) {
                    UVCCameraHelper.this.onFrame(byteBuffer);
                }
            }, 5);
            uVCCamera.startPreview();
            Log.w(TAG, "after startPreview");
            return Single.just(uVCCamera);
        }
        return Single.error(new Throwable("SurfaceTexture == null"));
    }

    public void setUpFPS(int i, int i2) {
        int i3 = 0;
        if (i < 30) {
            this.status.setVideoFrameFilter(5);
        } else {
            this.status.setVideoFrameFilter(0);
        }
        if (i2 < 10) {
            i3 = -7;
        } else if (i2 < 15) {
            i3 = -3;
        } else if (i2 < 20) {
            i3 = 1;
        } else if (i2 < 25) {
            i3 = 2;
        } else if (i2 < 30) {
            i3 = 4;
        }
        this.status.setStreamFrameFilter(i3);
        Log.w(TAG, "set frame filter local: " + this.status.getVideoFrameFilter() + " stream: " + this.status.getStreamFrameFilter());
    }

    private Size chooseUVCSize(List<Size> list, int i, int i2) {
        int videoWidth;
        int videoHeight;
        if (i2 != 0) {
            if (i2 == 1) {
                videoWidth = 1920;
                videoHeight = 1080;
            } else if (i2 != 2) {
                videoWidth = UVCCamera.DEFAULT_PREVIEW_WIDTH;
                videoHeight = UVCCamera.DEFAULT_PREVIEW_HEIGHT;
            } else {
                videoWidth = ZFYMediaManager.getInstance().getConfig().getStreamWidth();
                videoHeight = ZFYMediaManager.getInstance().getConfig().getStreamHeight();
            }
        } else if (this.isQRScan) {
            videoWidth = 640;
            videoHeight = 480;
        } else {
            videoWidth = ZFYMediaManager.getInstance().getConfig().getVideoWidth();
            videoHeight = ZFYMediaManager.getInstance().getConfig().getVideoHeight();
        }
        Size size = null;
        float f = videoHeight / videoWidth;
        for (Size size2 : list) {
            if (size2.width == videoWidth && size2.height == videoHeight) {
                return size2;
            }
            if (size == null) {
                Log.w(TAG, "size" + Math.abs(size2.height / size2.width) + " hw " + f);
                if (Math.abs((size2.height / size2.width) - f) < 0.01f) {
                    size = size2;
                }
            }
        }
        if (size == null) {
            size = list.get(0);
        }
        Log.w(TAG, "setCameraParameters: " + size.toString());
        return size;
    }

    @Override
    public Single<Boolean> capture() {
        this.needCaptrue.set(true);
        return Single.just(Boolean.TRUE);
    }

    @Override
    public void updateCameraStream(boolean z, boolean z2, boolean z3) {
        Log.w(TAG, "updateCameraStream needpreview: " + (z ? "true" : "false") + " needVideo: " + (z2 ? "true" : "false") + " needStream: " + (z3 ? "true" : "false"));
        this.status.setPreviewing(z);
        this.status.setRecording(z2);
        this.status.setRemoteing(z3);
        if (!this.isStartPreview.get()) {
            this.isStartPreview.set(true);
            startPreview(this.camera).subscribe(new SingleObserver<UVCCamera>() {
                @Override
                public void onError(Throwable th) {
                }

                @Override
                public void onSubscribe(Disposable disposable) {
                }

                @Override
                public void onSuccess(UVCCamera uVCCamera) {
                }
            });
        }
        if (z || z2 || z3) {
            return;
        }
        Log.e(TAG, "!needpreview && !needVideo && !needStream");
    }

    private Scheduler getBackgroundScheduler() {
        return AndroidSchedulers.from(getBackgroundThread().getLooper());
    }

    private synchronized HandlerThread getBackgroundThread() {
        if (this.backgroundThread == null) {
            HandlerThread handlerThread = new HandlerThread(TAG);
            this.backgroundThread = handlerThread;
            handlerThread.start();
        }
        return this.backgroundThread;
    }

    @Override
    public float getMaxZoomValue() {
        Log.w(TAG, "getMaxZoomValue");
        return 1.0f;
    }

    @Override
    public float getCurrentZoom() {
        return this.camera.getZoom();
    }

    @Override
    public Single<Boolean> closeCamera() {
        Log.w(TAG, "closeCamera");
        Single.just(Boolean.TRUE).observeOn(getBackgroundScheduler()).subscribe(new SingleObserver<Boolean>() {
            @Override
            public void onError(Throwable th) {
            }

            @Override
            public void onSubscribe(Disposable disposable) {
            }

            @Override
            public void onSuccess(Boolean bool) {
                if (UVCCameraHelper.this.camera != null) {
                    UVCCameraHelper.this.camera.getUsbControlBlock().close();
                }
            }
        });
        return closeCameraAction();
    }

    @Override
    public String getLocalizedName() {
        return getContext().getString(R.string.camera_name_build_external);
    }

    public synchronized Single<Boolean> closeCameraAction() {
        Log.w(TAG, "closeCameraAction");
        BehaviorSubject<Boolean> behaviorSubject = this.closeCameraSubject;
        if (behaviorSubject != null) {
            return behaviorSubject.firstOrError();
        }
        this.closeCameraSubject = BehaviorSubject.create();
        trueClose();
        return this.closeCameraSubject.firstOrError().doFinally(new Action() {
            @Override
            public void run() throws Exception {
                UVCCameraHelper.this.closeCameraSubject = null;
            }
        });
    }

    private void trueClose() {
        Single.just(Boolean.TRUE).observeOn(getBackgroundScheduler()).map(new Function<Boolean, Boolean>() {
            @Override
            public Boolean apply(Boolean bool) throws Exception {
                if (UVCCameraHelper.this.camera != null) {
                    UVCCamera uVCCamera = UVCCameraHelper.this.camera;
                    UVCCameraHelper.this.camera = null;
                    uVCCamera.stopCapture();
                    Log.w(UVCCameraHelper.TAG, "closeCamera close start");
                    uVCCamera.destroy();
                    Log.w(UVCCameraHelper.TAG, "closeCamera close end");
                } else {
                    Log.w(UVCCameraHelper.TAG, "camera null");
                }
                return Boolean.TRUE;
            }
        }).onErrorReturn(new Function<Throwable, Boolean>() {
            @Override
            public Boolean apply(Throwable th) throws Exception {
                th.printStackTrace();
                return Boolean.TRUE;
            }
        }).map(new Function<Boolean, Boolean>() {
            @Override
            public Boolean apply(Boolean bool) throws Exception {
                if (UVCCameraHelper.this.usbMonitor != null) {
                    Log.e(UVCCameraHelper.TAG, "usbMonitor unregister");
                    UVCCameraHelper.this.usbMonitor.unregister();
                    UVCCameraHelper.this.usbMonitor.destroy();
                    UVCCameraHelper.this.usbMonitor = null;
                }
                return Boolean.TRUE;
            }
        }).onErrorReturn(new Function<Throwable, Boolean>() {
            @Override
            public Boolean apply(Throwable th) throws Exception {
                th.printStackTrace();
                return Boolean.TRUE;
            }
        }).map(new Function<Boolean, Boolean>() {
            @Override
            public Boolean apply(Boolean bool) throws Exception {
                UVCCameraHelper.this.switchDevice(false);
                if (UVCCameraHelper.this.mPreviewSurface != null) {
                    UVCCameraHelper.this.mPreviewSurface.release();
                    Log.w(UVCCameraHelper.TAG, "closeCamera surface release");
                    UVCCameraHelper.this.mPreviewSurface = null;
                }
                return Boolean.TRUE;
            }
        }).onErrorReturn(new Function<Throwable, Boolean>() {
            @Override
            public Boolean apply(Throwable th) throws Exception {
                th.printStackTrace();
                return Boolean.TRUE;
            }
        }).doFinally(new Action() {
            @Override
            public void run() throws Exception {
                UVCCameraHelper.this.usbMonitor = null;
                UVCCameraHelper.this.camera = null;
            }
        }).delay(100L, TimeUnit.MILLISECONDS).subscribe(new SingleObserver<Boolean>() {
            @Override
            public void onSubscribe(Disposable disposable) {
            }

            @Override
            public void onSuccess(Boolean bool) {
                Log.e(UVCCameraHelper.TAG, "closeCameraSubject.onNext " + bool);
                if (UVCCameraHelper.this.closeCameraSubject != null) {
                    UVCCameraHelper.this.closeCameraSubject.onNext(bool);
                }
            }

            @Override
            public void onError(Throwable th) {
                if (UVCCameraHelper.this.closeCameraSubject != null) {
                    UVCCameraHelper.this.closeCameraSubject.onError(th);
                }
            }
        });
    }

    @Override
    public void onStatus(int i, int i2, int i3, int i4, ByteBuffer byteBuffer) {
        Log.w(TAG, "onStatus(statusClass=" + i + "; event=" + i2 + "; selector=" + i3 + "; statusAttribute=" + i4 + "; data=...)");
    }

    public byte[] getNV12(ByteBuffer byteBuffer) {
        byte[] obtainOutputData = YUVToolFactory.obtainOutputData(byteBuffer.remaining());
        byteBuffer.get(obtainOutputData, 0, byteBuffer.remaining());
        return obtainOutputData;
    }

    public boolean onResult(byte[] bArr) {
        if (this.status.isRecording() || this.status.isRemoteing()) {
            if (this.status.isRemoteing()) {
                byte[] obtainOutputData = YUVToolFactory.obtainOutputData(bArr.length);
                System.arraycopy(bArr, 0, obtainOutputData, 0, bArr.length);
                Log.w(TAG, "onRemoteStream");
                onRemoteStream(obtainOutputData, getPresentationTimeUs());
            }
            if (this.status.isRecording()) {
                Log.w(TAG, "onVideoStream");
                onVideoStream(bArr, getPresentationTimeUs());
                return true;
            }
            return true;
        } else if (this.needCaptrue.get() && ZFYLauncherJNI.NV12ToNV21(bArr, bArr, this.videoSize.width, this.videoSize.height) == 0) {
            onCaptureComplete(bArr, 17);
            this.needCaptrue.set(false);
            return true;
        } else {
            return true;
        }
    }

    @Override
    public void onFrame(ByteBuffer byteBuffer) {
        Log.e(TAG, "onFrame remaining" + byteBuffer.remaining());
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - this.lastTime > 1000) {
            this.lastTime = currentTimeMillis;
            Log.e(TAG, "fpsCounter: " + this.fpsCounter);
            this.fpsCounter = 0;
        } else {
            this.fpsCounter++;
        }
        Single.just(copyDirectByteBuffer(byteBuffer)).observeOn(getBackgroundScheduler()).map(new Function<ByteBuffer, byte[]>() {
            @Override
            public byte[] apply(ByteBuffer byteBuffer2) throws Exception {
                return UVCCameraHelper.this.getNV12(byteBuffer2);
            }
        }).map(new Function<byte[], Boolean>() {
            @Override
            public Boolean apply(byte[] bArr) throws Exception {
                return Boolean.valueOf(UVCCameraHelper.this.onResult(bArr));
            }
        }).subscribe(new SingleObserver<Boolean>() {
            @Override
            public void onSubscribe(Disposable disposable) {
            }

            @Override
            public void onSuccess(Boolean bool) {
            }

            @Override
            public void onError(Throwable th) {
                th.printStackTrace();
            }
        });
    }

    private ByteBuffer copyDirectByteBuffer(ByteBuffer byteBuffer) {
        ByteBuffer allocateDirect = ByteBuffer.allocateDirect(byteBuffer.remaining());
        allocateDirect.put(byteBuffer);
        allocateDirect.order(byteBuffer.order());
        allocateDirect.position(0);
        return allocateDirect.asReadOnlyBuffer();
    }

    public long getPresentationTimeUs() {
        return SystemClock.elapsedRealtimeNanos() / 1000;
    }

    @Override
    public Observable<ZFYCameraParameters> changePPI() {
        Size size;
        if (this.camera == null || (size = this.videoSize) == null) {
            return Observable.error(new Throwable(""));
        }
        Size size2 = null;
        float f = size.height / this.videoSize.width;
        Log.w(TAG, "before changePPI" + this.videoSize.toString());
        Iterator<Size> it = this.camera.getSupportedSizeList().iterator();
        boolean z = false;
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            Size next = it.next();
            if (Math.abs((next.height / next.width) - f) < 0.01f) {
                String str = TAG;
                Log.w(str, "in for" + next.toString());
                if (size2 == null) {
                    size2 = next;
                }
                if (z) {
                    Log.w(str, " targetSize = size");
                    size2 = next;
                    break;
                } else if (next.height == this.videoSize.height) {
                    Log.w(str, "targetNext");
                    z = true;
                }
            }
        }
        this.videoSize = size2;
        Log.w(TAG, "changePPI" + this.videoSize.toString());
        this.cameraParameters.setVideoWidth(this.videoSize.width);
        this.cameraParameters.setVideoHeight(this.videoSize.height);
        this.cameraParameters.setCaptrueHeight(this.videoSize.height);
        this.cameraParameters.setCaptrueWidth(this.videoSize.width);
        this.cameraParameters.setRemoteWidth(this.videoSize.width);
        this.cameraParameters.setRemoteHeight(this.videoSize.height);
        ZFYMediaConfig config = ZFYMediaManager.getInstance().getConfig();
        config.setVideoWidth(this.videoSize.width);
        config.setVideoHeight(this.videoSize.height);
        ZFYMediaManager.getInstance().changeConfig(config);
        updateCameraStream(true, false, false);
        return Observable.just(this.cameraParameters);
    }

    @Override
    public Single<ZFYCameraParameters> setUp() {
        return openCamera().map(new Function() {
            @Override
            public  Object apply(Object obj) {
                return UVCCameraHelper.this.cameraParameters;
            }
        });
    }

}
